package com.scud.product.config;

import com.scud.common.constants.RabbitmqConstants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author vermouth
 */

@Configuration
public class RabbitConfig {

    //声明订单处理消息队列
    @Bean
    public Queue orderQueue(){
        return QueueBuilder.durable(RabbitmqConstants.SCUD_ORDER_QUEUE).build();
    }

    //声明订单处理交换机
    @Bean
    public DirectExchange orderExchange(){
        return new DirectExchange(RabbitmqConstants.SCUD_ORDER_EXCHANGE,true,false);
    }

    //绑定交换机和消息队列
    @Bean
    public Binding bindingOrderDirect(Queue orderQueue,DirectExchange orderExchange){
        return BindingBuilder.bind(orderQueue)
                .to(orderExchange)
                .with(RabbitmqConstants.SCUD_ORDER_KEY);
    }
}
